<template>
    <div>
        <Form :model="form" label-position="left" :label-width="100">
            <FormItem label="填报部门"  prop="title" >
                <Input v-model="form.bmA" style="width: 25%;" disabled></Input>
            </FormItem>
        </Form>
        <Form :model="formValidate" :label-width="150">
            <label><b>业务流程梳理信息</b></label>
            <div class="ivu-alert ivu-alert-info">
                <span class="ivu-alert-message">
                    <FormItem label="行权业务清单" :required="true">
                        <Row>
                            <Col span="12">
                                 <wl-upload-oss-files
                                         v-model="formValidate.responsibility_list"
                                         :maxNum="50"
                                         uploadType="hadoop"
                                         uploadStyle="other"
                                         uploadUrl='http://218.60.17.11:33685/api/ac/file/fileCommonService/upLoadFiles'
                                         getSignUrl="/api/ac/jwork/getHadoopService/getSign"
                                         fileName="origin"
                                         :beforeUploadFilter="uploadFilter"
                                         :format="['doc','docx','pdf','xls','xlsx']"
                                         fileDir="/jov/">
                        </wl-upload-oss-files>
                            </Col>
                            <Col span="12" style="margin-left: 1px">附件上传,支持PDF、Word和Excel</Col>
                        </Row>
                    </FormItem>
                    <FormItem label="项目资金清单" :required="true">
                         <Row>
                            <Col span="11">
                                 <wl-upload-oss-files
                                         v-model="formValidate.special_funds"
                                         :maxNum="50"
                                         uploadType="hadoop"
                                         uploadStyle="other"
                                         uploadUrl='http://218.60.17.11:33685/api/ac/file/fileCommonService/upLoadFiles'
                                         getSignUrl="/api/ac/jwork/getHadoopService/getSign"
                                         fileName="origin"
                                         :beforeUploadFilter="uploadFilter"
                                         :format="['doc','docx','pdf','xls','xlsx']"
                                         fileDir="/jov/">
                        </wl-upload-oss-files>
                            </Col>
                            <Col span="13" style="margin-left: 1px">附件上传,上传预决算项目资金清单及政府大专项资金清单等,支持PDF、Word和Excel</Col>
                        </Row>
                    </FormItem>
                    <FormItem label="主要业务流程图" :required="true">
                         <Row>
                            <Col span="11">
                                 <wl-upload-oss-files
                                         v-model="formValidate.operation_flow"
                                         :maxNum="50"
                                         uploadType="hadoop"
                                         uploadStyle="other"
                                         uploadUrl='http://218.60.17.11:33685/api/ac/file/fileCommonService/upLoadFiles'
                                         getSignUrl="/api/ac/jwork/getHadoopService/getSign"
                                         fileName="origin"
                                         :beforeUploadFilter="uploadFilter"
                                         :format="['doc','docx','pdf','xls','xlsx']"
                                         fileDir="/jov/">
                                </wl-upload-oss-files>
                            </Col>
                            <Col span="13" style="margin-left: 1px">附件上传,支持PDF、Word和Excel</Col>
                        </Row>
                    </FormItem>
                    <FormItem label="信息系统清单"  :required="true">
                        <Row>
                            <Col span="4" style="margin-left: 1px">
                                <wl-upload-oss-files
                                        v-model="formValidate.information_systems"
                                        :maxNum="50"
                                        uploadType="hadoop"
                                        uploadStyle="other"
                                        uploadUrl='http://218.60.17.11:33685/api/ac/file/fileCommonService/upLoadFiles'
                                        getSignUrl="/api/ac/jwork/getHadoopService/getSign"
                                        fileName="origin"
                                        :beforeUploadFilter="uploadFilter"
                                        :format="['xls','xlsx']"
                                        fileDir="/jov/">
                                </wl-upload-oss-files>
                            </Col>
                             <Col span="20">
                                <span class="sps">请按照模板上传本单位正在运行中的信息系统清单，上传格式必须是Excel，下载模板请点击后面链接：<a href="http://house-manager.oss-cn-qingdao.aliyuncs.com/%E7%9B%91%E7%9D%A3%E6%B2%BB%E7%90%86%E4%BD%93%E7%B3%BB%E6%8F%90%E6%8A%A5/XX%E5%8D%95%E4%BD%8D%E7%8E%B0%E8%A1%8C%E4%BF%A1%E6%81%AF%E7%B3%BB%E7%BB%9F%E6%B8%85%E5%8D%95.xlsx"><Icon type="md-download" />《信息系统清单》</a></span>
                            </Col>
                        </Row>
                    </FormItem>
                </span>
            </div>
            <Row type="flex" justify="center" class="code-row-bg" style="margin-top: 20px">
                <Col :gutter="16" span="2">
                    <Button type="primary" @click="handleSubmit('formValidate')">保存</Button>
                </Col>
                <Col span="7">
                    <Button type="success" @click="ok()" :disabled ="nn">完成，并提报"梳理业务流程"信息</Button>
                </Col>
            </Row>
            <Row type="flex" justify="center" class="code-row-bg" style="margin-top: 20px">
                <Col span="10">
                    <span>点击【完成，并提报"梳理业务流程"信息】按钮后，仍可继续完善信息</span>
                </Col>
            </Row>
        </Form>
    </div>
</template>

<script>
import { operation, insertZlStateOperation, getCountStateList, updateOperation, countOperationState } from '@/api/user'

export default {

  name: 'test',

  data () {
    return {
      select_type: '',
      form: {
        bmA: ''
      },
      tm: '',
      companyCode: '',
      formValidate: {
        responsibility_list: '',
        special_funds: '',
        operation_flow: '',
        information_systems: ''
      },
      nn: false
    }
  },

  props: {

  },

  components: {

  },

  computed: {

  },

  methods: {
    async init () {
      countOperationState().then(ret => {
        console.log(ret.data.data, 'ret!!!!!!########')
        if (ret.data.data === 0 || ret.data.data === '') {
          this.select_type = '0'
        } else {
          this.select_type = '1'
        }
      })
      // this.formValidate = this.$route.params.aa || {}
      if (this.$route.params.aa !== undefined) {
        this.formValidate = this.$route.params.aa
        this.form.bmA = this.$route.params.aa.department_name
        this.companyCode = this.$route.params.aa.company_code
      } else {
        this.form.bmA = this.$store.state.user.severUserInfo.data.company_name
        console.log(this.tm)
      }
      getCountStateList({ 'step': '业务流程', companyCode: this.companyCode }).then(ret => {
        // console.log('bztj', ret.data.data[0].state)
        if (ret.data.data.length === 0) {
          return
        }
        if (ret.data.data[0].state === 'c') {
          this.nn = true
        }
      })
    },
    uploadFilter (file, uploadList, filterReturn) {
      console.log(this.url, 'uploadList')
      let isExit = false
      if (uploadList.length > 0) {
        uploadList.forEach(item => {
          if (item.url.indexOf(file.name) !== -1) {
            isExit = true
          }
        })
      }
      if (isExit) {
        this.errMsgAction(file.name, '【文件已经存在】')
        return { errcode: false, selfShow: true }
      }
      return { errcode: true }
    },
    handleSubmit () {
      if (this.formValidate.responsibility_list !== '' && this.formValidate.special_funds !== '' && this.formValidate.operation_flow !== '' && this.information_systems !== '') {
        console.log(this.formValidate)
        if (this.formValidate.id === undefined) {
          this.formValidate.select_type = this.select_type
          operation(this.formValidate).then(ret => {
            if (ret.data.errcode === 0) {
              this.$Message.success('成功')
              this.$router.push({
                name: 'operationFlows'
              })
            } else if (ret.data.errcode === 9999) {
              this.$Message.error('不能重复添加')
            }
          })
        } else {
          this.formValidate.select_type = this.select_type
          updateOperation(this.formValidate).then(ret => {
            if (ret.data.errcode === 0) {
              this.$Message.success('修改成功')
              this.$router.push({
                name: 'operationFlows'
              })
            } else {
              this.$Message.error('修改失败')
            }
          })
        }
      } else {
        this.$Message.error('请上传文件')
      }
      console.log('ss', this.formValidate)
    },
    ok () {
      if (this.formValidate.id === undefined) {
        this.formValidate.select_type = '1'
        operation(this.formValidate).then(ret => {
          if (ret.data.errcode === 0) {
            this.$Message.success('成功')
            this.$router.push({
              name: 'operationFlows'
            })
          } else if (ret.data.errcode === 9999) {
            this.$Message.error('不能重复添加')
          }
        })
      } else {
        this.formValidate.select_type = '1'
        updateOperation(this.formValidate).then(ret => {
          if (ret.data.errcode === 0) {
            this.$Message.success('成功')
            this.$router.push({
              name: 'operationFlows'
            })
          } else {
            this.$Message.error('失败')
          }
        })
      }
      let state = { state: 'c', 'step': '业务流程' }
      insertZlStateOperation(state).then(ret => {
        if (ret.data.errcode === 0) {
          getCountStateList({ 'step': '业务流程' }).then(ret => {
            let a = ret.data.data
            if (a[0].state === 'c') {
              this.nn = true
            }
          })
        }
      })
    }
  },

  watch: {

  },

  mounted () {
    this.init()
  }

}
</script>

<style scoped>
    .ivu-alert-info {
        border: 1px solid gainsboro;
        background-color: white;
    }
    .ivu-alert-infol {
        border: 1px solid gainsboro;
        background-color: white;
        text-align: center;
    }
    .ivu-alert {
        position: relative;
        padding: 8px 48px 8px 16px;
        border-radius: 4px;
        color: #515a6e;
        font-size: 14px;
        line-height: 16px;
        margin-bottom: 10px;
        margin-top: 20px;
    }
    .mid{
        text-align: center;
        margin-top: 20px
    }
    .sp{
        margin-left: 15px;
    }
    .sps{
        float: left;
    }
</style>
